package org.si.graphics;

import java.awt.Color;
import java.awt.Component;
import java.awt.GradientPaint;
import java.awt.Paint;

/**
 * Provides a Paint instance that draws a gradient between two points that are relational to the target paint area.
 *
 * @author Matt Nathan
 */
public class GradientPaintProvider implements PaintProvider {

    private final float x1;
    private final float y1;
    private final Color color1;
    private final float x2;
    private final float y2;
    private final Color color2;
    private final boolean cyclic;





    /**
     * Create a new GradientPaintProvider that will draw the gradient using a non-cyclic method between (x1, y1) and
     * (x2, y2).
     *
     * @param x1     Percentage of the width the first x coord should be at
     * @param y1     Percentage of the height the first y coord should be at
     * @param color1 The first color
     * @param x2     Percentage of the width the second x coord should be at
     * @param y2     Percentage of the height the second y coord should be at
     * @param color2 The second color
     */
    public GradientPaintProvider(float x1, float y1, Color color1, float x2, float y2, Color color2) {
        this(x1, y1, color1, x2, y2, color2, false);
    }





    /**
     * Create a new GradientPaintProvider that will draw a gradient between (x1, y1) and (x2, y2).
     *
     * @param x1     Percentage of the width the first x coord should be at
     * @param y1     Percentage of the height the first y coord should be at
     * @param color1 The first color
     * @param x2     Percentage of the width the second x coord should be at
     * @param y2     Percentage of the height the second y coord should be at
     * @param color2 The second color
     * @param cyclic Whether to draw a syclic gradient or not
     */
    public GradientPaintProvider(float x1, float y1, Color color1, float x2, float y2, Color color2, boolean cyclic) {
        this.x1 = x1;
        this.y1 = y1;
        this.color1 = color1;
        this.x2 = x2;
        this.y2 = y2;
        this.color2 = color2;
        this.cyclic = cyclic;
    }





    @Override
    public Paint get(Component c, int x, int y, int width, int height) {
        return new GradientPaint(x + x1 * width, y + y1 * width, color1,
                                 x + x2 * width, y + y2 * width, color2,
                                 cyclic);
    }





    public float getX1() {
        return x1;
    }





    public float getY1() {
        return y1;
    }





    public Color getColor1() {
        return color1;
    }





    public float getX2() {
        return x2;
    }





    public float getY2() {
        return y2;
    }





    public Color getColor2() {
        return color2;
    }





    public boolean isCyclic() {
        return cyclic;
    }
}
